/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.wip.graph.algo.ksp.srdrPaths;

import combi.graph.Mask;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import combi.utils.Couple;
import combi.wip.graph.algo.ksp.LabelGroupeSommets;
import combi.wip.graph.algo.ksp.threads.ThreadPourControleChemins;

import org.jgrapht.graph.DefaultDirectedWeightedGraph;
import org.jgrapht.graph.DefaultWeightedEdge;

public class ControleCheminsEnParalleleSRDR extends ThreadPourControleChemins{


	private List<Couple<Set<Integer>, Set<Integer>>> queries;
	private LabelGroupeSommets<Set<Integer>> labels;
	private DefaultDirectedWeightedGraph<Integer, DefaultWeightedEdge> graph;
	private int fakeSrc;
	private int fakeDest;
	private int k;
	private Map<Integer, Set<Integer>> twins;
	private String outFile;
	private Mask<Integer, DefaultWeightedEdge> maskBase;
	private boolean useRank;
	private double lengthPathLimit = Double.POSITIVE_INFINITY;

	public ControleCheminsEnParalleleSRDR(int nb_threads,
			DefaultDirectedWeightedGraph<Integer, DefaultWeightedEdge> graph,
			int fakeSrc,
			int fakeDest, 
			Mask<Integer, DefaultWeightedEdge> maskBase,
			int k,
			Map<Integer, Set<Integer>> twins,
			List<Couple<Set<Integer>, Set<Integer>>> queries,
			LabelGroupeSommets<Set<Integer>> labels,
			boolean useRank,
			String outFile)
	{
		super(nb_threads);
		this.fakeSrc = fakeSrc;
		this.fakeDest = fakeDest;
		this.queries = queries;
		this.labels = labels;
		this.outFile = outFile;
		this.graph = graph;
		this.maskBase = maskBase;
		this.k = k;
		this.twins = twins;
		this.useRank = useRank;
	}


	public void run()
	{
		int progression = 0;
		int total = queries.size();
		synchronized(this)
		{
			for (Couple<Set<Integer>, Set<Integer>> query : queries)
			{
				String debut = query.getFirst().toString();
				if (labels != null)
				{
					debut = labels.getLabel(query.getFirst());
				}
				String fin = query.getSecond().toString();
				if (labels != null)
				{
					fin = labels.getLabel(query.getSecond());
				}
				System.err.println(debut +" -> " + fin + " : " + progression*100/total + "% - " + new Date(java.lang.System.currentTimeMillis()));
				Thread t = new TraiteUnCheminSRDR(this, nb_threads,graph, maskBase, fakeSrc, fakeDest, k, twins, query, useRank, debut, fin, outFile);
				((TraiteUnCheminSRDR) t).setPathLengthLimit(lengthPathLimit);
				super.add();
				t.start();
				progression++;
			}
		}
	}


	public void setPathLengthLimit(double lengthPathLimit) {
		this.lengthPathLimit = lengthPathLimit;		
	}

}
